var formatTime = function(t) {
    var r = t.getFullYear(), e = t.getMonth() + 1, m = t.getDate(), o = t.getHours(), a = t.getMinutes(), u = t.getSeconds();
    return [ r, e, m ].map(formatNumber).join("/") + " " + [ o, a, u ].map(formatNumber).join(":");
}, formatNumber = function(t) {
    return (t = t.toString())[1] ? t : "0" + t;
};
var numberToFixed = function(num)
{
var result = num.substring(0,s.indexOf(".")+3);
return result
}

//保存图片到相册
var writePhotosAlbum = (successFun,failFun) =>{
  wx.getSetting({
    success(res) {
      if (!res.authSetting['scope.writePhotosAlbum']) {
        wx.authorize({
          scope: 'scope.writePhotosAlbum',
          success: function () {
            successFun && successFun()
          },
          fail: function (res) {
            wx.hideLoading()
            wx.showModal({
              title: '提示',
              content: "小程序需要您的微信授权保存图片，是否重新授权？",
              showCancel: true,
              cancelText: "否",
              confirmText: "是",
              success: function (res2) {
                if (res2.confirm) { //用户点击确定'
                  wx.openSetting({
                    success: (res3) => {
                      if (res3.authSetting['scope.writePhotosAlbum']) {
                        //已授权
                        successFun && successFun()
                      } else {
                        failFun && failFun()
                      }
                    }
                  })
                } else {
                  failFun && failFun()
                }
              }
            });
          }
        })
      } else {
        successFun && successFun()
      }
    }
  })
}
module.exports = {
    formatTime: formatTime,
    formatNumber: formatNumber,
    numberToFixed:numberToFixed,
    writePhotosAlbum:writePhotosAlbum
};